<template>
  <div>
    <el-form :inline="true" ref="form" :model="form" label-width="80px">
      <el-form-item label="">
        <el-input placeholder="用户名" v-model="form.userName"></el-input>
      </el-form-item>
      <el-button type="primary" class="el-icon-search">查询</el-button>
      <el-button>清空</el-button>
    </el-form>
    <div>
      <el-button type="primary">添加</el-button>
      <el-button type="danger">批量删除</el-button>
    </div>
    <div>
      <el-table :data="userList" style="width: 100%; margin-top: 20px" border>
        <el-table-column type="selection" label="label" width="width">
        </el-table-column>
        <el-table-column
          header-align="center"
          align="center"
          type="index"
          label="序号"
          width="80"
        >
        </el-table-column>
        <el-table-column
          header-align="center"
          align="center"
          prop="username"
          label="用户名"
          width="180"
        >
        </el-table-column>
        <el-table-column
          header-align="center"
          align="center"
          prop="nickName"
          label="用户昵称"
        >
        </el-table-column>
        <el-table-column
          header-align="center"
          align="center"
          prop="roleName"
          label="权限列表"
          width="width"
        >
        </el-table-column>
        <el-table-column
          header-align="center"
          align="center"
          prop="gmtCreate"
          label="创建时间"
        >
        </el-table-column>
        <el-table-column
          header-align="center"
          align="center"
          prop="gmtModified"
          label="更新时间"
          width="width"
        >
        </el-table-column>
        <el-table-column
          header-align="center"
          align="center"
          prop="prop"
          label="操作"
        >
        <template slot-scope="{row}">
         <el-button type="info" class="el-icon-user-solid" size="mini"></el-button>
         <el-button type="primary" class="el-icon-edit" size="mini"></el-button>
         <el-button type="danger" class="el-icon-delete" size="mini"></el-button>
        </template>
        </el-table-column>
      </el-table>
    </div>
    <!-- 分頁器 -->
    <el-pagination
      style="text-align: center"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="page"
      :page-sizes="[3, 5, 10]"
      :page-size="limit"
      layout="total, sizes, prev, pager, next, jumper"
      :total="totalCount"
    >
    </el-pagination>
  </div>
</template>

<script>
export default {
  name: "role",
  data() {
    return {
      page: 1,
      limit: 3,
      totalCount: 0,
      userList: [],
      form:{
        userName:''
      }
    };
  },
  mounted() {
    // 获取用户列表
    this.handleCurrentChange();
  },
  methods: {
    handleSizeChange(limit) {
      this.limit = limit;
      this.handleCurrentChange(this.userList.length > 0 ? this.page : this.page - 1);
    },
    async handleCurrentChange(pages = 1) {
        this.page = pages
        const {page,limit} = this
      let res = await this.$API.user.reqUserList(page,limit);
      if(res.code == 20000){
          this.userList = res.data.items
          this.totalCount = res.data.total
      }
    },
  },
};
</script>

<style>
</style>